package com.aspose.cells;

import java.util.Stack;

class zyg {
   private zaay a;
   private boolean b;
   private zaba c;
   private Stack d;
   private byte[] e;
   private int f;
   private boolean g;
   private int h = -1;

   zyg(zaay var1, byte[] var2, int var3, int var4) {
      this.a = var1;
      this.b = var1.p.Q.g;
      this.g = this.b;
      this.d = new Stack();
      this.e = var2;
      this.c = var1.f();
      this.c.a(this.e, this.f, var4);
   }

   zyg(zaay var1, byte[] var2, int var3, int var4, boolean var5) {
      this.a = var1;
      this.b = var5;
      this.g = this.b;
      this.d = new Stack();
      this.e = var2;
      this.c = var1.f();
      this.c.a(this.e, this.f, var4);
   }

   zyg(zaay var1, byte[] var2, zaba var3) {
      this.a = var1;
      this.b = var1.p.Q.g;
      this.g = this.b;
      this.d = new Stack();
      this.e = var2;
      this.c = var3;
   }

   public zagu a() {
      if (this.e == null) {
         return zzk.a;
      } else if (!this.c()) {
         return zzk.a;
      } else {
         if (this.d.size() != 1) {
            this.a("More than one token in stack");
         }

         return (zagu)this.d.pop();
      }
   }

   private boolean c() {
      while(this.c.e()) {
         this.f = this.c.c();
         switch(this.e[this.f]) {
         case 1:
         case 2:
            return false;
         case 3:
            this.a((zaag)(new zzm()));
            break;
         case 4:
            this.a((zaag)(new zzy()));
            break;
         case 5:
            this.a((zaag)(new zzz()));
            break;
         case 6:
            this.a((zaag)(new zzp()));
            break;
         case 7:
            this.a((zaag)(new zaad()));
            break;
         case 8:
            this.a((zaag)(new zzo()));
            break;
         case 9:
            this.a((zaag)(new zzv()));
            break;
         case 10:
            this.a((zaag)(new zzu()));
            break;
         case 11:
            this.a((zaag)(new zzq()));
            break;
         case 12:
            this.a((zaag)(new zzr()));
            break;
         case 13:
            this.a((zaag)(new zzs()));
            break;
         case 14:
            this.a((zaag)(new zaaa()));
            break;
         case 15:
            this.b(new zzt());
            break;
         case 16:
            this.b(new zzw());
            break;
         case 17:
            this.b(new zaae());
            break;
         case 18:
            this.a((zaaj)(new zaak()));
            break;
         case 19:
            this.a((zaaj)(new zaai()));
            break;
         case 20:
            this.a((zaaj)(new zaac()));
            break;
         case 21:
            this.c.b(this.f + 1);
            break;
         case 22:
            this.d.push(zzk.a);
            this.c.b(this.f + 1);
            break;
         case 23:
            this.d.push(new zaam(this.c.b()));
            break;
         case 24:
            switch(this.e[this.f + 1]) {
            case 7:
               this.d.push(new zyu(this.e, this.f, 6));
               this.c.b(this.f + 6);
               continue;
            case 25:
               this.d.push(new zaap(this.e, this.f));
               this.c.b(this.f + 14);
               continue;
            case 29:
               this.d.push(new zaao(this.e, this.f));
               this.c.b(this.f + 6);
               continue;
            default:
               this.d.push(zzk.a);
               this.c.b(this.f + 6);
               continue;
            }
         case 25:
            zagu var8;
            switch(this.e[this.f + 1]) {
            case 2:
               var8 = (zagu)this.d.peek();
               if (this.g && var8.d() == 64 && !var8.c(this.a)) {
                  this.e();
                  continue;
               }

               this.c.b(this.f + 4);
               continue;
            case 4:
               var8 = (zagu)this.d.peek();
               if (this.g && var8.d() == 64 && !var8.c(this.a)) {
                  this.d();
                  continue;
               }

               int var7 = com.aspose.cells.b.a.zc.e(this.e, this.f + 2) & '\uffff';
               this.c.b(this.f + var7 * 2 + 6);
               continue;
            case 16:
               zzi var6 = new zzi(64, zabk.a(4));
               var6.a((zagu[])(new zagu[]{(zagu)this.d.pop()}), (zaay)null);
               if (this.g) {
                  this.d.push(var6.d(this.a));
               } else {
                  this.d.push(var6);
               }

               this.c.b(this.f + 4);
               continue;
            default:
               this.c.h();
               continue;
            }
         case 26:
         case 27:
         case 38:
         case 39:
         case 40:
         case 41:
         case 46:
         case 47:
         case 48:
         case 49:
         case 50:
         case 51:
         case 52:
         case 53:
         case 54:
         case 55:
         case 56:
         case 62:
         case 63:
         case 70:
         case 71:
         case 72:
         case 73:
         case 78:
         case 79:
         case 80:
         case 81:
         case 82:
         case 83:
         case 84:
         case 85:
         case 86:
         case 87:
         case 88:
         case 94:
         case 95:
         case 102:
         case 103:
         case 104:
         case 105:
         case 110:
         case 111:
         case 112:
         case 113:
         case 114:
         case 115:
         case 116:
         case 117:
         case 118:
         case 119:
         case 120:
         default:
            if (this.c.h()) {
               break;
            }

            return false;
         case 28:
            zyz var5 = zyz.a(this.e[this.f + 1]);
            this.d.push(var5);
            this.c.b(this.f + 2);
            break;
         case 29:
            zyv var4 = this.e[this.f + 1] != 0 ? zyx.a : zyw.a;
            this.d.push(var4);
            this.c.b(this.f + 2);
            break;
         case 30:
            this.d.push(new zyy((double)com.aspose.cells.b.a.zc.e(this.e, this.f + 1)));
            this.c.b(this.f + 3);
            break;
         case 31:
            this.d.push(new zyy(com.aspose.cells.b.a.zc.f(this.e, this.f + 1)));
            this.c.b(this.f + 9);
            break;
         case 32:
         case 64:
         case 96:
            this.d.push(new zyt(this.c.a()));
            break;
         case 33:
         case 65:
         case 97:
            this.a(com.aspose.cells.b.a.zc.e(this.e, this.f + 1) & '\uffff', -1);
            this.c.b(this.f + 3);
            break;
         case 34:
         case 66:
         case 98:
            int var3 = this.e[this.f + 1] & 255 & 127;
            this.a(com.aspose.cells.b.a.zc.e(this.e, this.f + 2) & '\uffff' & 32767, var3);
            this.c.b(this.f + 4);
            break;
         case 35:
         case 57:
         case 67:
         case 89:
         case 99:
         case 121:
            zzj var1 = this.c.a(this.a.p.f);
            this.d.push(var1);
            if (!this.g || var1.l().f != null) {
               break;
            }

            zabk var2 = zabk.a(var1.l().e);
            if (var2 != null && var2.b() == 488) {
               this.g = false;
               this.h = this.d.size();
            }
            break;
         case 36:
         case 37:
         case 44:
         case 45:
         case 58:
         case 59:
         case 68:
         case 69:
         case 76:
         case 77:
         case 90:
         case 91:
         case 100:
         case 101:
         case 108:
         case 109:
         case 122:
         case 123:
            this.d.push(new zaal(zaaq.a(this.e[this.f]), this.c.a(this.a)));
            break;
         case 42:
         case 43:
         case 60:
         case 61:
         case 74:
         case 75:
         case 92:
         case 93:
         case 106:
         case 107:
         case 124:
         case 125:
            this.d.push(this.c.b(this.a));
         }
      }

      return true;
   }

   zaba b() {
      return this.c;
   }

   private void d() {
      int var1 = com.aspose.cells.b.a.zc.e(this.e, this.f + 2) & '\uffff';
      zagu var2 = ((zagu)this.d.pop()).e(this.a);
      if (var2 == null) {
         this.d.push(zzg.a);
      } else if (var2.b() == 0) {
         this.d.push(var2);
      } else {
         zyy var3 = var2.a(this.a, 7);
         if (var3 == null) {
            this.d.push(zzg.a);
         } else {
            int var4 = (int)var3.k();
            if (var4 > 0 && var4 <= var1) {
               this.f += 4;
               var4 <<= 1;
               int var5 = this.c.d();
               this.c.b(this.f + (com.aspose.cells.b.a.zc.e(this.e, this.f + var4 - 2) & '\uffff'));
               this.c.c(this.f + (com.aspose.cells.b.a.zc.e(this.e, this.f + var4) & '\uffff') - 4);
               if (!this.c()) {
                  this.a("Absent parameter for CHOOSE function");
               }

               this.c.b(this.c.d() + (com.aspose.cells.b.a.zc.e(this.e, this.c.d() + 2) & '\uffff') + 5);
               this.c.c(var5);
               return;
            }

            this.d.push(zzg.a);
         }
      }

      this.c.b(this.f + 8 + (com.aspose.cells.b.a.zc.e(this.e, this.f + 4 + (var1 << 1)) & '\uffff'));
   }

   private void e() {
      zagu var1 = ((zagu)this.d.pop()).e(this.a);
      int var2 = this.f + (com.aspose.cells.b.a.zc.e(this.e, this.f + 2) & '\uffff');
      if (this.e[var2] != 25 || this.e[var2 + 1] != 8) {
         this.a("Absent TAttrSkip for tAttrIf");
      }

      boolean var3 = false;
      boolean var4 = false;
      if (var1.b() == 0) {
         var4 = true;
         this.d.push(var1);
      } else {
         zyv var5 = var1.j(this.a);
         if (var5 == null) {
            var4 = true;
            this.d.push(zzg.a);
         } else {
            var3 = var5.k();
         }
      }

      if (var4) {
         this.c.b(var2 + (com.aspose.cells.b.a.zc.e(this.e, var2 + 2) & '\uffff') + 5);
      } else {
         int var7;
         if (var3) {
            var7 = this.c.d();
            this.c.b(this.f + 4);
            this.c.c(var2);
            if (!this.c()) {
               this.a("Absent parameter for TRUE of IF function");
            }

            this.c.b(var2 + (com.aspose.cells.b.a.zc.e(this.e, var2 + 2) & '\uffff') + 5);
            this.c.c(var7);
         } else {
            var7 = (com.aspose.cells.b.a.zc.e(this.e, var2 + 2) & '\uffff') + 1;
            if (var7 == 4) {
               this.d.push(zyw.a);
               this.c.b(var2 + 8);
            } else {
               var2 += 4;
               var7 += var2;
               this.c.b(var2);
               int var6 = this.c.d();
               this.c.c(var7 - 8);
               if (!this.c()) {
                  this.a("Absent parameter for FALSE of IF function");
               }

               this.c.b(var7);
               this.c.c(var6);
            }
         }

      }
   }

   private void a(int var1, int var2) {
      zzi var3 = null;
      zagu[] var4;
      if (var1 == 255) {
         var4 = new zagu[var2];
         if (var2 > this.d.size()) {
            this.b(var1, var2 - 1);
         }

         if (var2 > 1) {
            var4 = new zagu[var2 - 1];

            for(int var5 = var4.length - 1; var5 > -1; --var5) {
               var4[var5] = (zagu)this.d.pop();
            }
         }

         zagu var8 = (zagu)this.d.pop();
         switch(var8.b()) {
         case 7:
            var3 = (zzi)var8;
            break;
         case 8:
            zabk var6 = zabk.a(((zzj)var8).l().e);
            if (var6 == null) {
               var6 = zabk.b(((zzj)var8).l().e);
            } else if (this.b && !this.g && var6.b() == 488 && this.h >= this.d.size()) {
               this.g = true;
               this.h = -1;
            }

            var3 = new zzi(zaaq.a(this.e[this.f]), var6);
            break;
         default:
            throw new CellsException(5, "Unknown add-in function type: " + var8.b());
         }

         if (var2 > 1) {
            var3.a(var4, this.a);
         }
      } else {
         var4 = null;
         zabk var7;
         if (var2 == -1) {
            var7 = zabk.a(var1);
            if (var7 == null) {
               throw new CellsException(5, "Formula error: unknown function with id[" + var1 + "]");
            }

            var2 = var7.c().c();
         } else {
            var7 = zabk.a(var1 & 32767);
            if (var7 == null) {
               throw new CellsException(5, "Formula error: unknown function with id[" + var1 + "]");
            }
         }

         var3 = new zzi(zaaq.a(this.e[this.f]), var7);
         if (var2 > this.d.size()) {
            this.b(var1, var2);
         }

         if (var2 > 0) {
            zagu[] var9 = new zagu[var2];

            for(int var10 = var2 - 1; var10 > -1; --var10) {
               var9[var10] = (zagu)this.d.pop();
            }

            var3.a(var9, this.a);
         }
      }

      if (this.g && var3.d() == 64) {
         this.d.push(var3.d(this.a));
      } else {
         this.d.push(var3);
      }

   }

   private void b(int var1, int var2) {
      throw new CellsException(5, com.aspose.cells.b.a.zr.a(this.a.c((StringBuilder)null).append("-Invalid formula: expected ").append(var2).append(" but was ").append(this.d.size()).append(" parameters for function[").append(var1).append(']')));
   }

   private void a(String var1) {
      throw new CellsException(5, com.aspose.cells.b.a.zr.a(this.a.c((StringBuilder)null).append("-Invalid formula: ").append(var1)));
   }

   private void a(zaag var1) {
      var1.d((zagu)this.d.pop());
      var1.c((zagu)this.d.pop());
      if (this.g && var1.d() != 96) {
         this.d.push(var1.d(this.a));
      } else {
         this.d.push(var1);
      }

      this.c.b(this.f + 1);
   }

   private void a(zaaj var1) {
      var1.c((zagu)this.d.pop());
      if (this.g && var1.d() != 96) {
         this.d.push(var1.d(this.a));
      } else {
         this.d.push(var1);
      }

      this.c.b(this.f + 1);
   }

   private void b(zaag var1) {
      var1.d((zagu)this.d.pop());
      var1.c((zagu)this.d.pop());
      if (this.g) {
         this.d.push(var1.d(this.a));
      } else {
         this.d.push(var1);
      }

      this.c.b(this.f + 1);
   }
}
